const { data } = require('jquery');
const dbutil = require('../../../libs/MyDB');
module.exports = {

    //教师信息获取
    getInfo: async function () {
        let teachers = [];
        await dbutil.multiSelect('study_teacher', ['tname', 'school', 'class_name', 'jobId', 'description', 'password', 'teacher_id'])
            .then(
                result => {
                    teachers = result;
                }
            )
        return {
            code: 200,
            msg: "修改成功",
            teachers,
        }
    },
    addTeacher: async function (data) {
        let lodjobId = null;
        await dbutil.singleSelect('study_teacher',['jobId'],'jobId='+data.jobId)
            .then(
                result =>{
                    lodjobId = result.jobId;
                }
            )
        if(lodjobId != null){
            return {
                code: 401,
                msg: "已有该工号！",
            }
        }
        await dbutil.add('study_teacher', {
            tname: data.tname,
            school: data.school,
            class_name: data.className,
            jobId: data.jobId,
            password: data.password,
        })
        return {
            code: 200,
            msg: "新增成功",
        }
    },
    removeTeacher: async function(data){
        await dbutil.del('study_teacher',`jobId=${data.jobId}`);
        return {
            code: 200,
            msg: "删除成功",
        }
    },
    setTeacher: async function(data){
        await dbutil.update('study_teacher',`jobId=${data.jobId}`, {
            tname: data.tname,
            school: data.school,
            class_name: data.className,
            jobId: data.jobId,
            password: data.password,
        });
        return {
            code: 200,
            msg: "修改成功",
        }
    }

}